//
//  AppDelegate.m
//  ZKCompetitionApp
//
//  Created by 凯朱 on 2019/8/20.
//

#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import "IQKeyboardManager.h"
#import "AvoidCrash.h"
#import "OSUserGuideVC.h"
@interface AppDelegate (){
}
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 启动图片延时: 1秒
//    NSTimeInterval delayDuration = 1.0;
//    NSTimer *connectionTimer = [NSTimer scheduledTimerWithTimeInterval:delayDuration target:self selector:@selector(timerFired:) userInfo:nil repeats:NO];
//    [[NSRunLoop currentRunLoop] addTimer:connectionTimer forMode:NSDefaultRunLoopMode];
//    do {
//        // 设置1.0秒检测做一次do...while的循环
//        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
//    } while (!done);
    //开启防崩溃框架
    [AvoidCrash becomeEffective];
    //键盘弹出监听
    [self registerIQKeyboardManager];
    [[OSUserManager sharedOSUserManager] confingUserInfo];
    //开启引导页
    [self startGuideApp];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    return YES;
}

BOOL done;
- (void)timerFired:(NSTimer *)timer {
    done = YES;
}


-(void)startGuideApp{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = OSWhiteColor;
    [self.window makeKeyAndVisible];
    [[UIButton appearance] setExclusiveTouch:YES];
    [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = OSWhiteColor;
    if (@available(iOS 11.0, *)){
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    }
//    OSUserGuideVC *guideVc = [OSUserGuideVC new];
//    kWeakSelf(self)
//    guideVc.GuideBlock = ^{
//        [self setUpTabVc];
//    };
    [self setUpTabVc];
//    [UIApplication sharedApplication].delegate.window.rootViewController = guideVc;
    [[UIApplication sharedApplication].delegate.window makeKeyAndVisible];
}

#pragma mark ————— 初始化window —————
-(void)setUpTabVc{
    OSTabBarController *tab = [OSTabBarController new];
    self.window.rootViewController = tab;
}


#pragma mark -————— 键盘弹出监听 —————
-(void)registerIQKeyboardManager{
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    manager.shouldResignOnTouchOutside = YES;
    manager.shouldToolbarUsesTextFieldTintColor = YES;
    manager.enableAutoToolbar = NO;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    
   
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

@end
